//
//  SYDBaseViewController.m
//  PinGJByOwnerSide
//
//  Created by lantaiyuan on 2017/8/8.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

#import "SYDBaseViewController.h"

@interface SYDBaseViewController ()

@end

@implementation SYDBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = CONTENT_BG_COLOR;
    [self.view addSubview:self.mineCenterView];
}
#pragma mark - 导航栏
-(SYDMineCenterView *)mineCenterView{
    if (!_mineCenterView) {
        if (iPhone8_X) {
            _mineCenterView = [[SYDMineCenterView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 222)];
        } else {
            _mineCenterView = [[SYDMineCenterView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
        }
        
        _mineCenterView.title = self.navigationItem.title;
    }
    return _mineCenterView;
}

#pragma mark - 标准首页导航栏(已和UI确认,暂时用安卓的标注图 20 + 48)

#pragma mark - 右导航栏按钮

/**
 添加右导航栏按钮
 
 @param image 图片
 @param click 点击回调
 */
- (void)rightNavButtonWithImage:(UIImage *)image action:(void(^)(void))click{
    
    UIImageView * rightImageView = [[UIImageView alloc] init];
    rightImageView.image = image;
    rightImageView.contentMode = UIViewContentModeCenter;
    [self.mineCenterView addSubview:rightImageView];
    
    UIButton * btn = [[UIButton alloc] init];
    [self.mineCenterView addSubview:btn];
    WEAKSELF
    if (iPhone8_X) {
        [rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.mineCenterView.mas_right).offset(-15);
            make.top.equalTo(@55);
            make.width.equalTo(@24);
            make.height.equalTo(@24);
        }];
        
        
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.mineCenterView.mas_right).offset(0);
            make.top.equalTo(@44);
            make.width.equalTo(@52);
            make.height.equalTo(@44);
        }];
    } else {
        [rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.mineCenterView.mas_right).offset(-15);
            make.top.equalTo(@31);
            make.width.equalTo(@24);
            make.height.equalTo(@24);
        }];
        
        
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.mineCenterView.mas_right).offset(0);
            make.top.equalTo(@20);
            make.width.equalTo(@52);
            make.height.equalTo(@44);
        }];
    }
    
    [btn jk_touchDown:^{
        click();
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    
}
/**
 添加右导航栏按钮
 
 @param title 标题
 @param click 点击回调
 */
- (void)rightNavButtonWithTitle:(NSString *)title action:(void(^)(void))click{
    UIButton * btn = [[UIButton alloc] init];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor colorWithHexString:@"ffffff"] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.mineCenterView addSubview:btn];
    
    CGFloat width = [NSString boundingRectWithString:title font:btn.titleLabel.font].width;
    
    WEAKSELF
    NSInteger topConstraint;
    if (iPhone8_X) {
        topConstraint = 55;
    } else {
        topConstraint = 20;
    }
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.mineCenterView.mas_right).offset(-15);
        make.top.equalTo(@(topConstraint));
        make.width.equalTo(@(width + 0.25));
        make.height.equalTo(@44);
    }];
    [btn jk_touchDown:^{
        click();
    }];
}

/**
 添加右导航栏按钮
 
 @param title 标题
 @param color 颜色
 @param click 点击回调
 */
- (void)rightNavButtonWithTitle:(NSString *)title color:(UIColor *)color action:(void(^)(void))click{
    UIButton * btn = [[UIButton alloc] init];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:color forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.mineCenterView addSubview:btn];
    
    CGFloat width = [NSString boundingRectWithString:title font:btn.titleLabel.font].width;
    
    WEAKSELF
    NSInteger topConstraint;
    if (iPhone8_X) {
        topConstraint = 55;
    } else {
        topConstraint = 20;
    }
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.mineCenterView.mas_right).offset(-15);
        make.top.equalTo(@(topConstraint));
        make.width.equalTo(@(width + 0.25));
        make.height.equalTo(@44);
    }];
    
    [btn jk_touchDown:^{
        click();
    }];
}

//标准版首页导航栏添加右导航按钮(切换城市)
- (void)travelRightNavButtonWithTitle:(NSString *)title color:(UIColor *)color imageName:(NSString *)imageName action:(void(^)(void))click{
    
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.image = [UIImage imageNamed:imageName];
    [self.mineCenterView addSubview:imageView];
    
    WEAKSELF
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.mineCenterView.mas_right).offset(-15);
        make.top.equalTo(weakSelf.mineCenterView.mas_top).offset(39.5);
    }];
    
    UIButton *btn = [[UIButton alloc]init];
    
    if (title.length >= 4) {
        title = [title substringToIndex:4];
    }
    
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:color forState:UIControlStateNormal];
    
    if (title.length >= 4) {
        btn.titleLabel.font = [UIFont systemFontOfSize:10];
    }else if (title.length == 3){
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
    }else{
        btn.titleLabel.font = [UIFont systemFontOfSize:19];
    }
    
    [self.mineCenterView addSubview:btn];
    
    CGFloat btnWidth = [NSString boundingRectWithString:title font:btn.titleLabel.font].width;
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(imageView.mas_left).offset(-6);
        make.width.equalTo(@(btnWidth + 0.25));
        make.centerY.equalTo(imageView.mas_centerY);
    }];
    
    UIButton *coverBtn = [[UIButton alloc]init];
    [self.mineCenterView addSubview:coverBtn];
    
    [coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(btn.mas_left).offset(0);
        make.right.equalTo(weakSelf.mineCenterView.mas_right).offset(-15);
        make.centerY.equalTo(imageView.mas_centerY);
        make.height.equalTo(@44);
    }];
    
    [coverBtn jk_touchDown:^{
        click();
    }];
}

#pragma mark - 左导航栏按钮
/**
 添加左导航栏按钮
 
 @param image 图片
 @param click 点击回调
 */
- (void)leftNavButtonWithImage:(UIImage *)image action:(void (^)(void))click{
    UIImageView * leftNavImageView = [[UIImageView alloc] init];
    leftNavImageView.image = image;
    [self.mineCenterView addSubview:leftNavImageView];
    
    UIButton * backBtn = [[UIButton alloc] init];
    [self.mineCenterView addSubview:backBtn];
    
    WEAKSELF
    NSInteger topHeight;
    NSInteger btnTopHeight;
    if (iPhone8_X) {
        topHeight = 55;
        btnTopHeight = 44;
    } else {
        topHeight = 31;
        btnTopHeight = 20;
    }
    [leftNavImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mineCenterView.mas_left).offset(10);
        make.top.equalTo(@(topHeight));
        make.width.equalTo(@22);
        make.height.equalTo(@22);
    }];
    if ([YMSaveTool isLogin]) {
        leftNavImageView.layer.cornerRadius = 11;
        leftNavImageView.layer.masksToBounds = YES;
    }
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mineCenterView.mas_left).offset(0);
        make.top.equalTo(@(btnTopHeight));
        make.width.equalTo(@44);
        make.height.equalTo(@44);
    }];
    
    [backBtn jk_touchDown:^{
        click();
    }];
}

/**
 添加左导航栏按钮
 
 @param title 图片
 @param click 点击回调
 */
- (void)leftNavButtonWithTitle:(NSString *)title action:(void (^)(void))click{
    UIImageView * backImageView = [[UIImageView alloc] init];
    backImageView.image = [UIImage imageNamed:@"nav_button_return"];
    backImageView.userInteractionEnabled = YES;
    [self.mineCenterView addSubview:backImageView];
    
    UILabel * label = [[UILabel alloc] init];
    label.text = title;
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:15];
    label.adjustsFontSizeToFitWidth = YES;
    [self.mineCenterView addSubview:label];
    
    UIButton * backBtn = [[UIButton alloc] init];
    [self.mineCenterView addSubview:backBtn];
    
    WEAKSELF
    NSInteger topHeight;
    NSInteger btnTopHeight;
    if (iPhone8_X) {
        topHeight = 55;
        btnTopHeight = 44;
    } else {
        topHeight = 31;
        btnTopHeight = 20;
    }
    [backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mineCenterView.mas_left).offset(10);
        make.top.equalTo(@(topHeight));
        make.width.equalTo(@22);
        make.height.equalTo(@22);
    }];
    
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backBtn.mas_right).offset(-20);
        make.top.equalTo(@(topHeight));
        make.width.equalTo(@80);
        make.height.equalTo(@22);
    }];
    
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mineCenterView.mas_left).offset(0);
        make.top.equalTo(@(btnTopHeight));
        make.width.equalTo(@54);
        make.height.equalTo(@44);
    }];
    
    [backBtn jk_touchDown:^{
        click();
    }];
}


/**
 添加左导航栏按钮(返回按钮)
 
 @param click 点击回调
 */
- (void)backButtonAction:(void (^)(void))click{
    
    UIImageView * backImageView = [[UIImageView alloc] init];
    backImageView.image = [UIImage imageNamed:@"nav_button_return"];
    backImageView.userInteractionEnabled = YES;
    [self.mineCenterView addSubview:backImageView];
    
    UIButton * backBtn = [[UIButton alloc] init];
    [self.mineCenterView addSubview:backBtn];
    
    WEAKSELF
    NSInteger topHeight;
    NSInteger btnTopHeight;
    if (iPhone8_X) {
        topHeight = 55;
        btnTopHeight = 44;
    } else {
        topHeight = 31;
        btnTopHeight = 20;
    }
    [backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mineCenterView.mas_left).offset(10);
        make.top.equalTo(@(topHeight));
        make.width.equalTo(@20);
        make.height.equalTo(@20);
    }];
    
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mineCenterView.mas_left).offset(0);
        make.top.equalTo(@(btnTopHeight));
        make.width.equalTo(@44);
        make.height.equalTo(@44);
    }];
    
    [backBtn jk_touchDown:^{
        click();
    }];
}

//标准版首页左导航按钮
- (void)travelLeftNavButtonAction:(void(^)(void))click{
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:[UIImage imageNamed:@"nav_button_return"] forState:UIControlStateNormal];
    [self.mineCenterView addSubview:btn];
    
    WEAKSELF
    NSInteger topHeight;
    if (iPhone8_X) {
        topHeight = 55;
    } else {
        topHeight = 31;
    }
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mineCenterView.mas_left).offset(15);
        make.top.equalTo(@(topHeight));
        make.width.equalTo(@23);
        make.height.equalTo(@23);
    }];
    
    UIButton *coverBtn = [[UIButton alloc]init];
    [self.mineCenterView addSubview:coverBtn];
    
    [coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(btn.mas_left).offset(-15);
        make.right.equalTo(btn.mas_right).offset(15);
        make.centerY.equalTo(weakSelf.mineCenterView.mas_centerY).offset(10);
        make.height.equalTo(@44);
    }];
    
    
    
    [coverBtn jk_touchDown:^{
        click();
    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

